package beautiful.butterfly.drds.datasource.connection_contexts.spi;

//import beautiful.butterfly.drds.datasource.author.Author;
//import beautiful.butterfly.drds.datasource.author.Authors;

import beautiful.butterfly.drds.datasource.connection_contexts.api.IRowDataMapList;
import beautiful.butterfly.drds.datasource.connection_contexts.api.ISql;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.sql.*;

//@Author(name = Authors.LI_YANG)
public final class RowDataMapList implements IRowDataMapList {
    public static final Logger logger = LoggerFactory.getLogger(RowDataMapList.class);

    private final ISql sql;
    private final ResultSet resultSet;
    protected boolean closed = false;

    //
    public RowDataMapList(ISql sql, ResultSet resultSet) {
        super();
        this.sql = sql;
        this.resultSet = resultSet;
    }

    public ISql getSql() {
        return sql;
    }

    public ResultSet getResultSet() {
        return resultSet;
    }

    //
    protected SQLException checkException(Exception e) throws SQLException {
        logger.error(e.getMessage());
        return ((Sql) this.sql).handleException(e);
    }

    //
    public void setFetchDirection(int fetchDirection) throws SQLException {
        try {
            this.resultSet.setFetchDirection(fetchDirection);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public int getFetchDirection() throws SQLException {
        try {
            return this.resultSet.getFetchDirection();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public void setFetchSize(int fetchSize) throws SQLException {
        try {
            this.resultSet.setFetchSize(fetchSize);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public int getFetchSize() throws SQLException {
        try {
            return this.resultSet.getFetchSize();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public void beforeFirst() throws SQLException {
        try {
            this.resultSet.beforeFirst();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean isBeforeFirst() throws SQLException {
        try {
            return this.resultSet.isBeforeFirst();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean first() throws SQLException {
        try {
            return this.resultSet.first();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean isFirst() throws SQLException {
        try {
            return this.resultSet.isFirst();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean previous() throws SQLException {
        try {
            return this.resultSet.previous();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean next() throws SQLException {
        try {
            return this.resultSet.next();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean last() throws SQLException {
        try {
            return this.resultSet.last();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean isLast() throws SQLException {
        try {
            return this.resultSet.isLast();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public void afterLast() throws SQLException {
        try {
            this.resultSet.afterLast();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean isAfterLast() throws SQLException {
        try {
            return this.resultSet.isAfterLast();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public void close() throws SQLException {
        try {
            this.closed = true;
            this.resultSet.close();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean isClosed() throws SQLException {
        return this.closed;
    }

    public ResultSetMetaData getResultSetMetaData() throws SQLException {
        try {
            return this.resultSet.getMetaData();
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public boolean getBoolean(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getBoolean(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public boolean getBoolean(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getBoolean(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //

    public short getShort(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getShort(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public short getShort(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getShort(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public int getInt(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getInt(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public int getInt(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getInt(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public long getLong(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getLong(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public long getLong(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getLong(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public float getFloat(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getFloat(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public float getFloat(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getFloat(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public double getDouble(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getDouble(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public double getDouble(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getDouble(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public String getString(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getString(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public String getString(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getString(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getBigDecimal(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getBigDecimal(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //

    public Date getDate(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getDate(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public Date getDate(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getDate(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public Time getTime(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getTime(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public Time getTime(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getTime(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public Timestamp getTimestamp(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getTimestamp(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public Timestamp getTimestamp(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getTimestamp(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    //
    public Object getObject(String columnLabel) throws SQLException {
        try {
            return this.resultSet.getObject(columnLabel);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

    public Object getObject(int columnIndex) throws SQLException {
        try {
            return this.resultSet.getObject(columnIndex);
        } catch (Exception t) {
            throw checkException(t);
        }
    }

}
